<template>
  <div class="my-tabbar">
    <ul>
      <li @click="itemClick(index)" class="item" v-for="(item, index) in list" :key="item.text">
        <div class="text" :class="index === current ? 'active' : ''">{{ item.text }}</div>
        <div class="arrow-container" v-if="index === 1">
          <van-icon name="arrow-up" :color="state==='up'?'#CEA62A':''" />
          <van-icon name="arrow-down" :color="state==='down'?'#CEA62A':''" />
        </div>
      </li>
    </ul>
  </div>
</template>
<script setup>
import { ref } from 'vue'
const emit = defineEmits('tabbarChangeEvent')
const current = ref(0)
const state = ref('default') // default up down
const list = ref([
  {
    text: '综合'
  },
  {
    text: '价格'
  },
  {
    text: '分类'
  },
])

const itemClick = (idx) => {
  current.value = idx
  if(idx===1){
    if(state.value === 'default' || state.value === 'down'){
      state.value = 'up'
    }else if(state.value === 'up'){
      state.value = 'down'
    }
  }else {
    state.value = 'default'
  }

  // 发送事件
  emit('tabbarChangeEvent',state.value)
}











</script>
<style lang="scss" scoped>
.my-tabbar {
  height: 100px;
  background-color: #fff;

  ul {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 90px;

    .item {
      display: flex;
      height: 100px;

      .text {
        line-height: 100px;
        font-family: PingFangSC-Regular;
        font-size: 28px;
        color: #212121;
        letter-spacing: 0;
        font-weight: 400;
      }

      .active {
        font-family: PingFangSC-Medium;
        font-size: 28px;
        color: #CEA62A;
        letter-spacing: 0;
        font-weight: 500;
      }

      .arrow-container {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
      }
    }

  }

  :deep(.van-icon-arrow-down:before){
    top:-2px;
  }
  :deep(.van-icon-arrow-up:before){
    top:4px;
  }
}
</style>